package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlDataFields entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlDataFields
 * @author MyEclipse Persistence Tools
 */

public class MdlDataFieldsDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlDataFieldsDAO.class);
	// property constants
	public static final String DATAID = "dataid";
	public static final String TYPE = "type";
	public static final String NAME = "name";
	public static final String DESCRIPTION = "description";
	public static final String PARAM1 = "param1";
	public static final String PARAM2 = "param2";
	public static final String PARAM3 = "param3";
	public static final String PARAM4 = "param4";
	public static final String PARAM5 = "param5";
	public static final String PARAM6 = "param6";
	public static final String PARAM7 = "param7";
	public static final String PARAM8 = "param8";
	public static final String PARAM9 = "param9";
	public static final String PARAM10 = "param10";

	public void save(MdlDataFields transientInstance) {
		log.debug("saving MdlDataFields instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlDataFields persistentInstance) {
		log.debug("deleting MdlDataFields instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlDataFields findById(java.lang.Long id) {
		log.debug("getting MdlDataFields instance with id: " + id);
		try {
			MdlDataFields instance = (MdlDataFields) getSession().get(
					"idv.loveloser.dao.MdlDataFields", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlDataFields instance) {
		log.debug("finding MdlDataFields instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlDataFields")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlDataFields instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlDataFields as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByDataid(Object dataid) {
		return findByProperty(DATAID, dataid);
	}

	public List findByType(Object type) {
		return findByProperty(TYPE, type);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByDescription(Object description) {
		return findByProperty(DESCRIPTION, description);
	}

	public List findByParam1(Object param1) {
		return findByProperty(PARAM1, param1);
	}

	public List findByParam2(Object param2) {
		return findByProperty(PARAM2, param2);
	}

	public List findByParam3(Object param3) {
		return findByProperty(PARAM3, param3);
	}

	public List findByParam4(Object param4) {
		return findByProperty(PARAM4, param4);
	}

	public List findByParam5(Object param5) {
		return findByProperty(PARAM5, param5);
	}

	public List findByParam6(Object param6) {
		return findByProperty(PARAM6, param6);
	}

	public List findByParam7(Object param7) {
		return findByProperty(PARAM7, param7);
	}

	public List findByParam8(Object param8) {
		return findByProperty(PARAM8, param8);
	}

	public List findByParam9(Object param9) {
		return findByProperty(PARAM9, param9);
	}

	public List findByParam10(Object param10) {
		return findByProperty(PARAM10, param10);
	}

	public List findAll() {
		log.debug("finding all MdlDataFields instances");
		try {
			String queryString = "from MdlDataFields";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlDataFields merge(MdlDataFields detachedInstance) {
		log.debug("merging MdlDataFields instance");
		try {
			MdlDataFields result = (MdlDataFields) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlDataFields instance) {
		log.debug("attaching dirty MdlDataFields instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlDataFields instance) {
		log.debug("attaching clean MdlDataFields instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}